<?php

namespace app\tours\model;

use think\Model;

class UserLine extends Model {

        protected function _before_insert(&$data, $options = array()) {
                parent::_before_insert($data, $options);
                //获取sessionid 
                if (empty($data['uid'])) {
                        $data['uid'] = $_SESSION['uid'];
                }
                $data['create_time'] = time();
        }


        protected function _after_select(&$resultSet, $options = array()) {
                parent::_after_select($resultSet, $options);
                $tourModel = D('Tours');
                foreach ($resultSet as $key => $value) {
                        $t_where['id'] = $value['tours_id'];
                        $toursInfo = $tourModel->relation(true)->where($t_where)->select();
                        $resultSet[$key]['title'] = $toursInfo[0]['title'];
                        $resultSet[$key]['images_full'] = $toursInfo[0]['images_full'];
                        $resultSet[$key]['price'] = $toursInfo[0]['price'];
                        $resultSet[$key]['url'] = $toursInfo[0]['url'];
                }
        }

}
